import os
import pandas as pd
import numpy as np
from PIL import Image
from pandas import Series,DataFrame
def multilabel(indirec,y):
    num1=len(indirec);
    label=np.zeros([num1,10])
    label=label.astype(np.str)
    num2=y.shape[1];
    for i in range(y.shape[0]):
        if y[i][1]!='0.0':
           label[i][0]=y[i][0]
    df=pd.DataFrame(y,index=list(y[:,0]),columns=['id','label1','intensity1',
    'label2','intensity2','label3','intensity3','label4','intensity4','label5'])
    df=df.drop('id',1)
    for i in range(num1):
        for j in range(len(df.iloc[i])):
            df.iloc[i][j]=float(df.iloc[i][j])
    df1=df.sum(axis=1)
    df['label_sum']=df1
    label1=list(df['label1'].unique())
    label2=list(df['label2'].unique())
    label3=list(df['label3'].unique())
    label4=list(df['label4'].unique())
    label=label1+label2+label3+label4
    label=set(label)
    label_list=list(label)
    label_list=label_list[1:];
    au_len=len(label_list)
    label_result=np.zeros([num1,au_len]);
    for j in range(au_len):
        for i in range(num1):
            if label_list[j] in [(list(df.iloc[i]))[0],(list(df.iloc[i]))[2],
            (list(df.iloc[i]))[4],(list(df.iloc[i]))[6]]:
                label_result[i][j]=1
            else:
                label_result[i][j]=0
    intensity_result=np.zeros([num1,au_len]);
    for i in range(num1):
        temp=[(list(df.iloc[i]))[0],(list(df.iloc[i]))[2],(list(df.iloc[i]))[4],        (list(df.iloc[i]))[6]];
        for j in range(au_len):
            if label_list[j] in temp:
               intensity_result[i][j]=float(df.iloc[i][2*(temp.index(label_list[j]))+1])
            else:
               intensity_result[i][j]=0.0
    return label_result,intensity_result
